import {
  createBrowserRouter,
  createHashRouter,
  Navigate,
  Outlet,
  RouteObject,
} from "react-router-dom";
import Error403 from "@lgq/pages/Error403";
import Error404 from "@lgq/pages/Error404";
import Error500 from "@lgq/pages/Error500";
import LoginFC from "@lgq/pages/login/Login";
import HomeLayout from "@lgq/layouts";
import Analysis from "@lgq/pages/dashboard/analysis";
import Workbench from "@lgq/pages/dashboard/workbench";
import { title } from "process";
import DashBoard from "@lgq/pages/dashboard";
import AuthLoader from "./AuthLoader";
import path from "path";
import Operation from "@lgq/pages/dashboard/analysis/operation";

const dashboardRoutes: RouteObject[] = [
  { index: true, element: <Navigate to={"workbench"} replace /> },
  {
    path: "workbench",
    element: <Workbench />,
  },
  {
    path: "analysis",
    element: <Analysis />,
    children: [
      { index: true, element: <Navigate to={"operation"} replace /> },
      {
        index: true,
        path: "operation",
        element:<Operation/>
      }
    ]
  },
];

export const routers = [
  {
    path: "/login",
    element: <LoginFC />,
  },
  {
    path: "/",
    element: <HomeLayout />,
    id: "layout",
    loader: AuthLoader,
    children: [
      { index: true, element: <Navigate to={"dashboard"} replace /> },
      {
        path: "dashboard",
        element: <Outlet />,
        children: dashboardRoutes,
      },
    ],
  },
  {
    path: "*",
    element: <Navigate to="/404" />,
  },
  {
    path: "/403",
    element: <Error403 />,
  },
  {
    path: "/404",
    element: <Error404 />,
  },
  {
    path: "/500",
    element: <Error500 />,
  },
];

//组件路由
// export default function Router() {
//   return useRoutes(routers);
// }

const router = createBrowserRouter(routers);

//API 路由
export default router;
